const Main = imports.ui.main;
const Params = imports.misc.params;
+let _capturedEventId = 0;
+let _grabHelperStack = [];
+function _onCapturedEvent(actor, event) {
+ let grabHelper = _grabHelperStack[_grabHelperStack.length - 1];
+ return grabHelper.onCapturedEvent(event);
+}
+
+function _pushGrabHelper(grabHelper) {
+ _grabHelperStack.push(grabHelper);
+
+ if (_capturedEventId == 0)
+ _capturedEventId = global.stage.connect('captured-event', _onCapturedEvent);
+}
+
+function _popGrabHelper(grabHelper) {
+ let poppedHelper = _grabHelperStack.pop();
+ if (poppedHelper != grabHelper)
+ throw new Error("incorrect grab helper pop");
+
+ if (_grabHelperStack.length == 0) {
+ global.stage.disconnect(_capturedEventId);
+ _capturedEventId = 0;
+ }
+}
+
// GrabHelper:
// @owner: the actor that owns the GrabHelper
// @params: optional parameters to pass to Main.pushModal()
this._grabStack = [];
this._actors = [];
- this._capturedEventId = 0;
this._ignoreRelease = false;
this._modalCount = 0;
if (!Main.pushModal(this._owner, this._modalParams))
return false;
- this._capturedEventId = global.stage.connect('captured-event', Lang.bind(this, this._onCapturedEvent));
+ _pushGrabHelper(this);
}
this._modalCount++;
if (this._modalCount > 0)
return;
- global.stage.disconnect(this._capturedEventId);
- this._capturedEventId = 0;
+ _popGrabHelper(this);
this._ignoreRelease = false;
}
},
- _onCapturedEvent: function(actor, event) {
+ onCapturedEvent: function(event) {
let type = event.type();
if (type == Clutter.EventType.KEY_PRESS &&